/*define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'machine/index',
                    add_url: 'machine/add',
                    edit_url: 'machine/edit',
                    del_url: 'machine/del',
                    multi_url: 'machine/multi',
                    table: 'machine',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'function', title: __('Function')},
                        {field: 'stop', title: __('Stop')},
                        {field: 'bpa', title: __('Bpa')},
                        {field: 'bpc', title: __('Bpc')},
                        {field: 'bpd', title: __('Bpd')},
                        {field: 'bpg', title: __('Bpg')},
                        {field: 'bpi', title: __('Bpi')},
                        {field: 'bpj', title: __('Bpj')},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
*/
define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {

    var Controller = {
        index: function () {
            // 基于准备好的dom，初始化echarts实例
            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            // 指定图表的配置项和数据
            var option = {
                 tooltip : {
					trigger: 'axis',
					axisPointer : {            // 坐标轴指示器，坐标轴触发有效
						type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
					}
				},
				legend: {
					data:['支出', '收入']
				},
				grid: {
					left: '3%',
					right: '4%',
					bottom: '3%',
					containLabel: true
				},
				xAxis : [
					{
						type : 'value'
					}
				],
				yAxis : [
					{
						type : 'category',
						axisTick : {show: false},
						data : ['周一','周二','周三','周四','周五','周六','周日']
					}
				],
				series : [
					/* {
						name:'利润',
						type:'bar',
						label: {
							normal: {
								show: true,
								position: 'inside'
							}
						},
						data:[200, 170, 240, 244, 200, 220, 210]
					}, */
					{
						name:'收入',
						type:'bar',
						stack: '总量',
						label: {
							normal: {
								show: true
							}
						},
						data:[320, 302, 341, 374, 390, 450, 420]
					},
					{
						name:'支出',
						type:'bar',
						stack: '总量',
						label: {
							normal: {
								show: true,
								position: 'left'
							}
						},
						data:[-120, -132, -101, -134, -190, -230, -210]
					}
				]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);

            //动态添加数据，可以通过Ajax获取数据然后填充
           /* setInterval(function () {
                Orderdata.column.push((new Date()).toLocaleTimeString().replace(/^\D* /, ''));
                var amount = Math.floor(Math.random() * 200) + 20;
                Orderdata.createdata.push(amount);
                Orderdata.paydata.push(Math.floor(Math.random() * amount) + 1);

                //按自己需求可以取消这个限制
                if (Orderdata.column.length >= 20) {
                    //移除最开始的一条数据
                    Orderdata.column.shift();
                    Orderdata.paydata.shift();
                    Orderdata.createdata.shift();
                }
                myChart.setOption({
                    xAxis: {
                        data: Orderdata.column
                    },
                    series: [{
                            name: __('Sales'),
                            data: Orderdata.paydata
                        },
                        {
                            name: __('Orders'),
                            data: Orderdata.createdata
                        }]
                });
            }, 2000);*/
            $(window).resize(function () {
                myChart.resize();
            });

            $(document).on("click", ".btn-checkversion", function(){
                top.window.$("[data-toggle=checkupdate]").trigger("click");
            });

            //读取FastAdmin的更新信息和社区动态
            $.ajax({
                url: Config.fastadmin.api_url + '/news/index',
                type: 'post',
                dataType: 'jsonp',
                success: function (ret) {
                    $("#news-list").html(Template("newstpl", {news: ret.newslist}));
                }
            });
            $.ajax({
                url: Config.fastadmin.api_url + '/forum/discussion',
                type: 'post',
                dataType: 'jsonp',
                success: function (ret) {
                    $("#discussion-list").html(Template("discussiontpl", {news: ret.discussionlist}));
                }
            });
        }
    };

    return Controller;
});